| Conditions | 1 |
| Paths | 1 |
| Total Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 31 | $.fn.symphonyAffix = function(options) { |
||
| 32 | var objects = $(this), |
||
| 33 | settings = { |
||
| 34 | // public |
||
| 35 | container: null, |
||
| 36 | // private |
||
| 37 | top: 0, |
||
| 38 | freespace: 0, |
||
| 39 | bottom: 0, |
||
| 40 | height: 0, |
||
| 41 | maxtop: 0 |
||
| 42 | }; |
||
| 43 | |||
| 44 | $.extend(settings, options); |
||
| 45 | |||
| 46 | |||
| 47 | /*--------------------------------------------------------------------- |
||
| 48 | Initialisation |
||
| 49 | ---------------------------------------------------------------------*/ |
||
| 50 | |||
| 51 | objects.each(function createOneAffix() { |
||
| 52 | var itemSettings = $.extend({}, settings); |
||
| 53 | var item = $(this); |
||
| 54 | var updateItemSettings = function () { |
||
| 55 | itemSettings.top = itemSettings.container.offset().top; |
||
| 56 | itemSettings.freespace = itemSettings.container.height(); |
||
| 57 | itemSettings.bottom = itemSettings.top + itemSettings.freespace; |
||
| 58 | itemSettings.height = item.height(); |
||
| 59 | itemSettings.maxtop = (itemSettings.freespace - itemSettings.height) + 'px'; |
||
| 60 | }; |
||
| 61 | |||
| 62 | // use parent as default container |
||
| 63 | if (!itemSettings.container) { |
||
| 64 | itemSettings.container = item.parent(); |
||
| 65 | } |
||
| 66 | |||
| 67 | // resolve jQuery object |
||
| 68 | else { |
||
| 69 | itemSettings.container = $(itemSettings.container); |
||
| 70 | } |
||
| 71 | |||
| 72 | // cache cssom values |
||
| 73 | updateItemSettings(); |
||
| 74 | item.on('updatesettings.affix', updateItemSettings); |
||
| 75 | |||
| 76 | item.addClass('js-affix'); |
||
| 77 | |||
| 78 | // save instance settings |
||
| 79 | item.data('affix-settings', itemSettings); |
||
| 80 | |||
| 81 | // register instance |
||
| 82 | instances = instances.add(item); |
||
| 83 | }); |
||
| 84 | |||
| 85 | // Init |
||
| 86 | $(window).triggerHandler('scroll'); |
||
| 87 | |||
| 88 | return objects; |
||
| 89 | }; |
||
| 90 | |||
| 120 |
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.